package com.cnfangmao.masterdata.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cnfangmao.masterdata.dao.BasicDataFieldMappingDao;
import com.cnfangmao.masterdata.dto.BasicDataFieldMappingSearchDto;
import com.cnfangmao.masterdata.dto.GeneralSearchDto;
import com.cnfangmao.masterdata.model.BasicDataFieldMapping;
import com.cnfangmao.masterdata.service.BasicDataFieldMappingService;

/**
 * <p>
 * 主数据与业务系统字段映射表 服务实现类
 * </p>
 *
 * @author chenxd
 * @since 2020-04-14
 */
@Service
public class BasicDataFieldMappingServiceImpl extends ServiceImpl<BasicDataFieldMappingDao, BasicDataFieldMapping> implements BasicDataFieldMappingService {
	
	@Autowired
	private BasicDataFieldMappingDao dao;
	
	@Override
	public BasicDataFieldMapping findByBasicDataFieldMappingCode(
			String businessFieldCode) {
		BasicDataFieldMapping  basicDataFieldMapping =null;
		QueryWrapper<BasicDataFieldMapping>  queryWrapper =new QueryWrapper<BasicDataFieldMapping>();
		queryWrapper.eq("business_field_code", businessFieldCode);
		basicDataFieldMapping=dao.selectOne(queryWrapper);
		return basicDataFieldMapping;
	}

	@Override
	public BasicDataFieldMapping findByBasicDataFieldMappingName(
			String businessFieldName) {
		BasicDataFieldMapping basicDataFieldMapping=null;
		QueryWrapper<BasicDataFieldMapping> queryWrapper =new QueryWrapper<BasicDataFieldMapping>();
		queryWrapper.eq("business_field_name", businessFieldName);
		basicDataFieldMapping=dao.selectOne(queryWrapper);
		return basicDataFieldMapping;
	}

	@Override
	public IPage<BasicDataFieldMapping> queryListBasicDataFieldMapping(
			GeneralSearchDto<BasicDataFieldMappingSearchDto> dto) {
		IPage<BasicDataFieldMapping> page = dao.selectPage(new Page<>(dto.getPageNo(), dto.getPageSize()),
				new QueryWrapper<BasicDataFieldMapping>().
				like(StringUtils.isNotEmpty(dto.getConditions().getBusinessFieldName()), "business_field_name", dto.getConditions().getBusinessFieldName())
				.or().like(StringUtils.isNotEmpty(dto.getConditions().getBusinessFieldCode()), "business_field_code", dto.getConditions().getBusinessFieldCode())
				);
		return page;
	}

}
